package com.coda.clouddisk.exception;

import com.coda.clouddisk.entity.KesunReturn;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 捕获业务异常
     */
    @ExceptionHandler
    public KesunReturn exceptionHandler(BaseException exception){
        log.info("捕获业务异常{}",exception.getMessage());
        KesunReturn back = new KesunReturn();
        back.setCode(exception.getCode());
        back.setMsg(exception.getMessage());
        return back;
    }
}
